<template>
	<section>

		<!--列表-->
		<el-table :data="tableData" highlight-current-row v-loading="listLoading" style="width: 100%;">
			<el-table-column type="index" label="序号" width="60" align='center'>
				<template slot-scope="scope">   
                    {{pageSize*(nowPage-1)+scope.$index+1}}
                </template>
			</el-table-column>
			<el-table-column prop="classesName" label="班级名称" min-width="190" align='center' >
			</el-table-column>
			<el-table-column prop="phaseName" label="学段" min-width="120" align='center'>
			</el-table-column>
			<el-table-column prop="enterYear" label="入学年份" min-width="100" align='center' >
			</el-table-column>
			<el-table-column prop="graduateYear" label="毕业年份" min-width="100" align='center' >
			</el-table-column>
			<el-table-column prop="teacherName" label="班主任" min-width="100" align='center' >
			</el-table-column>
			<el-table-column label="操作" width="320" align='center' fixed='right'>
				<template slot-scope="scope">
					<el-button v-if="checkMenu('/classesteacher')>=0" type="success" size="small" @click="handleSubjectTeacher(scope.row)">任课教师</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="text-align: center; ">
			</el-pagination>
		</el-col>
		
	</section>
</template>

<script>
	import util from '../../common/js/util'
	import { SysApi } from '@/api/index'
	import axios from 'axios';

	export default {
		data() {
			return {
				filters: {
					schoolId: JSON.parse(sessionStorage.getItem("schoolId")),
					phaseId: '',
					gradeId: '',
					isGraduated: 1
					
				},
				tableData: [],
				schoolName: '',
				classesId: '',
				classesName: '',
				teacherName: '',
				schoolId:  JSON.parse(sessionStorage.getItem("schoolId")),
				menuList: [],
				total: 0,
				listLoading: true,

				pageSize:10,
				nowPage:1,

			}
		},
		created(){
			if(this.$route.params.schoolId != undefined){
				sessionStorage.setItem("schoolId", JSON.stringify(this.$route.params.schoolId));
				this.schoolId = this.$route.params.schoolId;
			}else{
				this.schoolId = JSON.parse(sessionStorage.getItem("schoolId"));
			}  
			
			this.getMenuList();
			this.getClassesList();
			this.getPhaseList();

		},
		mounted() {
			this.getClassesList();
		},
		methods: {

			handleCurrentChange(val) {
				this.nowPage = val;
				this.getClassesList();
			},
			getMenuList(){
				this.menuList = sessionStorage.getItem('menuList');
			},
			
			//获取班级列表
			getClassesList() {
				let params = {
					pageNum: this.nowPage,
					pageSize: this.pageSize,
					schoolId: this.schoolId,
					phaseId: this.filters.phaseId,
					gradeId: this.filters.gradeId,
					isGraduated: 1

				};
				this.listLoading = true;

				SysApi.getAllClassesListPage(params,res =>{
					this.total = res.total;
					this.tableData = res.list;
					this.listLoading = false;
				}, (errorType, error) => {
					this.listLoading = false;
				})


			},
			handleSubjectTeacher(row){
				this.$router.push({
					name:'任课教师管理',
					params:{
						phaseId: row.phaseId,
						classesId: row.classesId,
						classesName: row.classesName
					}
				});
			},
			error_current_change(errorNowPage){
				this.errorNowPage = errorNowPage;
			},
			//判断菜单是否可见
			checkMenu(item){

				if (this.menuList==null || this.menuList.length==0)
				{
					return -1;
				}
				var index = this.menuList.indexOf(item);
				return index
			}

	},
		
}

</script>

<style>
.el-table >.el-table__fixed {
    height: 100% !important; 
  }
.el-table >.el-table__fixed-right {
    height: 100% !important; 
  }
.el-table--scrollable-x .el-table__body-wrapper {
    z-index: 1;
  }
</style>